<?php

defined('__MAPEXEC__') or die('No direct access allowed');

class Maps_Icon_Manager_Common extends Maps_Collection {
  
  private $exportEnabled = true;
  
  /**
   * Checks this icon manager to see if it can be exported.
   * @param   void
   * @return  boolean True if it can be exported
   */
  public function canExport() {
    return $this->exportEnabled;
  }
  
  /**
   * Helper function to create a new icon object.
   * @param   string  Service name, e.g. "google"
   * @param   string  Icon type
   * @param   string  Optional base URL for icon images
   * @return  string  New icon Id
   */
  protected function createIcon($service, $type, $baseURL='') {
    $baseClass = 'Maps_Icon_Common';
    $serviceBaseClass = 'Maps_Icon_' . ucfirst($service) . '_Common';
    $serviceClass = 'Maps_Icon_' . ucfirst($service) . '_' . ucfirst($type);
    $icon = null;
    
    if ( !class_exists($baseClass) ) {
      require_once("$baseClass.class.php");
    }
    
    if ( !class_exists($serviceBaseClass) ) {
      require_once("$serviceBaseClass.class.php");
    }
    
    if ( !class_exists($serviceClass) ) {
      require_once("$serviceClass.class.php");
      if ( file_exists(dirname(__FILE__) . "/$serviceClass.class.php") ) {
        require_once("$serviceClass.class.php");
      } else {
        $serviceClass = $serviceBaseClass;
      }
    }
    
    $icon = new $serviceClass($baseURL);
    $icon->setId($type);
    return $this->add($icon);
  }
  
  /**
   * Disables this icon manager's ability to be exported.
   * @param   void
   * @return  void
   */
  public function disableExport() {
    $this->exportEnabled = false;
  }
  
  /**
   * Enables this icon manager's ability to be exported.
   * @param   void
   * @return  void
   */
  public function enableExport() {
    $this->exportEnabled = false;
  }
  
}

?>